<template>
  <el-dialog title="修改内链信息" :visible="visible" @close="handleClose">
    <el-form label-width="90px">
      <el-form-item label="排序" prop="sort">
              <el-input-number v-model="form.sort" :min="0" :controls="false"></el-input-number>
            </el-form-item>
      <el-form-item label="锚文本" prop="anchorText">
        <el-input v-model="form.anchorText"></el-input>
      </el-form-item>
      <el-form-item label="锚文本地址" prop="anchorUrl">
        <el-input v-model="form.anchorUrl" ></el-input>
      </el-form-item>
       <el-form-item label="是否支持文章内链" prop="isArticleLink" >
            <el-switch
              v-model="value"
              active-color="#409EFF"
              inactive-color="#C0CCDA">
            </el-switch>
          </el-form-item>
      <el-form-item label="内链位置" prop="anchorPosition">
        <el-input v-model="form.anchorPosition" ></el-input>
      </el-form-item>
      <!-- <el-form-item label="联系方式" prop="contactWay">
        <el-input v-model="form.contactWay" ></el-input>
      </el-form-item>
       <el-form-item label="站点介绍" prop="introduce">
        <el-input v-model="form.introduce" type="textarea"></el-input>
      </el-form-item>  -->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    props: ['visible', 'data', 'type'],
    data () {
      return {
        value:null,
        form: {
          sort:'',
          anchorText: '',
          anchorUrl:'',
          anchorPosition:'',
          isArticleLink:''
        },
        formData:{
          sort:'',
          anchorText: '',
          anchorUrl:'',
          anchorPosition:'',
          isArticleLink:''
        }
      }
    },
    created(){
      this.form = this.data;
      this.formData = JSON.stringify(this.form)
      if(this.form.isArticleLink=="0"){
          this.value=false
      }else{
          this.value=true
      }
    },
    methods: {
      handleClose() {
        let formData = JSON.parse(this.formData);
        this.form = formData;
        this.$emit('save', true)
        // this.$emit('editCancle', true)
      },
      onSubmit() {
        if(this.value==true){
            this.form.isArticleLink='1'
        }else{
            this.form.isArticleLink='0'
        }
        const params = {
          ...this.form,
        }
        this.$api.internalLink.update(params).then(res => {
          if(res.success) {
            this.$message.success('修改成功')
            this.$emit('save', true)
          }
        })
      }
    }
  }
</script>
